package org.ucas.kgraph.controller;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ucas.kgraph.dto.ErrDto;
import org.ucas.kgraph.utils.exception.ExceptionUtil;
import org.ucas.kgraph.utils.exception.RestException;

@ControllerAdvice
public class DefaultExceptionHandler {
  protected static final Logger logger = Logger.getLogger(DefaultExceptionHandler.class);

  /**
   * 处理应用级别的异常,本处暂时处理所有RestException
   * @param e
   * @return
   */
  @ExceptionHandler(RestException.class)
  @ResponseBody
  protected ErrDto handleException(RuntimeException e){
    e.printStackTrace();
    return ExceptionUtil.toDto(e);
  }

}
